package com.ruoyi.web.controller.system;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TOngoodsshelfBak;
import com.ruoyi.system.service.ITOngoodsshelfBakService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库查询Controller
 *
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/system/BAK")
public class TOngoodsshelfBakController extends BaseController
{
    @Autowired
    private ITOngoodsshelfBakService tOngoodsshelfBakService;

    /**
     * 首次查询入库查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:list')")
    @GetMapping("/first")
    public TableDataInfo first(TOngoodsshelfBak tOngoodsshelfBak)
    {
        startPage();
        LocalDate today=LocalDate.now();
        String endsTime = String.valueOf(today);
        List<TOngoodsshelfBak> list = tOngoodsshelfBakService.selectFirstTOngoodsshelfBakList(tOngoodsshelfBak);
        return getDataTable(list);
    }

    /**
     * 查询入库查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOngoodsshelfBak tOngoodsshelfBak)
    {
        startPage();
        String[] addTimes = tOngoodsshelfBak.getONDATEs();
        if (addTimes != null && addTimes.length > 1) {
            tOngoodsshelfBak.setStartTime(addTimes[0]);
            tOngoodsshelfBak.setEndsTime(addTimes[1]);
        }
        List<TOngoodsshelfBak> list = tOngoodsshelfBakService.selectTOngoodsshelfBakList(tOngoodsshelfBak);
        return getDataTable(list);
    }

    /**
     * 导出入库查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:export')")
    @Log(title = "入库查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOngoodsshelfBak tOngoodsshelfBak)
    {
        List<TOngoodsshelfBak> list = tOngoodsshelfBakService.selectTOngoodsshelfBakList(tOngoodsshelfBak);
        ExcelUtil<TOngoodsshelfBak> util = new ExcelUtil<TOngoodsshelfBak>(TOngoodsshelfBak.class);
        util.exportExcel(response, list, "入库查询数据");
    }

    /**
     * 获取入库查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:query')")
    @GetMapping(value = "/{lotId}")
    public AjaxResult getInfo(@PathVariable("lotId") String lotId)
    {
        return success(tOngoodsshelfBakService.selectTOngoodsshelfBakByLotId(lotId));
    }

    /**
     * 新增入库查询
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:add')")
    @Log(title = "入库查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOngoodsshelfBak tOngoodsshelfBak)
    {
        return toAjax(tOngoodsshelfBakService.insertTOngoodsshelfBak(tOngoodsshelfBak));
    }

    /**
     * 修改入库查询
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:edit')")
    @Log(title = "入库查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOngoodsshelfBak tOngoodsshelfBak)
    {
        return toAjax(tOngoodsshelfBakService.updateTOngoodsshelfBak(tOngoodsshelfBak));
    }

    /**
     * 删除入库查询
     */
    @PreAuthorize("@ss.hasPermi('system:BAK:remove')")
    @Log(title = "入库查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lotIds}")
    public AjaxResult remove(@PathVariable String[] lotIds)
    {
        return toAjax(tOngoodsshelfBakService.deleteTOngoodsshelfBakByLotIds(lotIds));
    }
}
